import React, { Component } from 'react'
import './FunctionButton.css'
import { HashRouter as Router, Route, NavLink, Switch, Redirect } from 'react-router-dom';

import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { getsplist, getappoint, getcollect } from '../../redux/actionCreator';

class FunctionButton extends Component {
    constructor(props) {
        super(props)
        this.props.dispatch(getsplist())
        this.props.dispatch(getcollect(JSON.parse(localStorage.getItem('user')).user_id))
        this.props.dispatch(getappoint(JSON.parse(localStorage.getItem('user')).user_id))
    }
    render() {
        return <Router>
            <nav>
                <ul className="FunctionButton" style={{ marginTop: '8em' }}>
                    <li style={{ textAlign: 'center' }} onClick={() => {
                        this.props.history.push('/appo')
                        let appolist = [];
                        this.props.shop.map((item, index) => {
                            this.props.yuding.map((i, idx) => {
                                if (item.commodity_id === i.commoditya_id) {
                                    appolist.push(item);
                                }
                            })
                        })
                        localStorage.setItem('yuding', JSON.stringify(appolist));
                    }} >
                        <i className="iconfont icon-icon"></i>
                        <div>已预约</div>
                    </li>

                    <li style={{ textAlign: 'center' }} onClick={() => {
                        this.props.history.push('/collect')
                        let collelist = [];
                        this.props.shop.map((item) => {
                            this.props.shoucang.map((i) => {
                                if (item.commodity_id === i.commodity_id) {
                                    collelist.push(item);
                                }
                            })
                        })
                        localStorage.setItem('shoucang', JSON.stringify(collelist));
                    }} >
                        <i className="iconfont icon-xin"></i>
                        <div>已收藏</div>
                    </li>

                    <li style={{ textAlign: 'center' }} onClick={() => {
                        this.props.history.push('/release')
                    }} >
                        <i className="iconfont icon-fabuxuqiu"></i>
                        <div>我的发布</div>
                    </li>

                    <li style={{ textAlign: 'center' }} onClick={() => {
                        this.props.history.push('/setup')
                    }} >
                        <i className="iconfont icon-shezhi1"></i>
                        <div>设置</div>
                    </li>

                </ul>
            </nav>

        </Router>

    }
}
const mapStateToProps = (state) => (
    {
        shop: state.shop,
        yuding: state.yuding,
        shoucang: state.shoucang
    }
)

export default withRouter(connect(mapStateToProps)(FunctionButton))
